using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.Xpo;
using Component;
using System.Collections;
namespace Component
{
    public class ContactDB : Base
    {
        /// <summary>
        /// GetAll()
        /// </summary>
        /// <returns>XPCollection<Contact></returns>
        public static XPCollection<Contact> GetAll()
        {
           XPCollection<Contact> _xpContact = new XPCollection<Contact>(KetNoiCSDL.session);
           _xpContact.Sorting = SetupSort(ColumContact._Date,false);
            return _xpContact;
        }
       /// <summary>
        ///    public static XPCollection<Contact> GetAllContactInMonth()
       /// </summary>
       /// <returns></returns>
        public static ArrayList GetAllContactInMonth(int month)
        {
            XPCollection<Contact> _xpContact = GetAll();
            ArrayList al = new ArrayList();
            foreach (Contact contact in _xpContact)
            {
                if (contact.Date.Date.Month == month)
                {
                    al.Add(contact);
                }
            }
            return al;
        }
        /// <summary>
        /// GetContactById(int id)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Contact GetObjectByid(int id,bool admin)
        {
            XPCollection<Contact> _xpContact = new XPCollection<Contact>(KetNoiCSDL.session);
            _xpContact.Filter = FilterAll(admin);
            return _xpContact.Lookup(id);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="admin"></param>
        /// <returns></returns>
        public static Contact GetObjectByIdCart(int idCart, bool admin)
        {
            XPCollection<Contact> _xpContact = new XPCollection<Contact>(KetNoiCSDL.session);
            _xpContact.Filter = FilterByString(ColumContact._Cart,idCart,admin);
            if (_xpContact.Count > 0)
            { return _xpContact[0]; }
            return null;
        }   
    }
}
